<?php if (($section == "comments") || ($section == "view_comments")) { 
$query_readings = sprintf("SELECT * FROM readings WHERE id='%s'", $row_view_specific['id']); 
// $row_view_specific['id'] variable is inherited from the comments.sec.php module
$readings= mysql_query($query_readings, $connection) or die(mysql_error());
$row_readings = mysql_fetch_assoc($readings);
$totalRows_readings = mysql_num_rows($readings);
?>
<div id="comment-preview">
<h1>Module <?php echo $row_readings['mid']; ?> Reading Assignment</h1>
<p><?php echo get_material_info($row_readings['reading_material'],"name",1); if ($row_readings['reading_assignment'] != "") echo "<br>".$row_readings['reading_assignment']; if ($row_readings['reading_notes'] != "") echo "<br><em>".$row_readings['reading_notes']."</em>"; ?></p>
</div>
<?php } // end if ($section == "comments")
else 
{ 
$query_readings = sprintf("SELECT * FROM readings WHERE cid='%s' AND mid='%s'", $cid, $row_modules['mid']); 
$readings= mysql_query($query_readings, $connection) or die(mysql_error());
$row_readings = mysql_fetch_assoc($readings);
$totalRows_readings = mysql_num_rows($readings);

?>
<h3>Module <?php echo $row_modules['mid']; ?> Readings</h3>
<?php if ($modal_window != "true") { ?><div class="stacked"><span class="icon"><img src="images/page_add.png" border="0" align="absmiddle" /></span><a id="modal_window_link" href="index.php?section=module_readings&amp;action=add&amp;dbTable=readings&amp;cid=<?php echo $cid."&mid=".$row_modules['mid']; ?>&amp;modal_window=true">Add a Reading Assignment to Module <?php echo $row_modules['mid']; ?>?</a></div><?php } ?>
<table class="dataTable">
    <tr>
        <th class="data">Titles</th>
        <th class="data" width="10%">ID/Reviewer<br />Comments?</th>
        <th class="data" width="30%">Changes<br />Needed?</th>
        <th class="data" width="23%">Actions</th>
  </tr>
<?php
	if ($totalRows_readings > 0) {
	do { 
		$query_reading_comments = sprintf("SELECT * FROM comments WHERE cid='%s' AND tableName='readings' AND rid='%s'", $cid, $row_readings['id']);
		$reading_comments = mysql_query($query_reading_comments, $connection) or die(mysql_error());
		$row_reading_comments = mysql_fetch_assoc($reading_comments);
		$totalRows_reading_comments = mysql_num_rows($reading_comments);
	?>
	<tr style="background-color: <?php echo $color; ?>">
		<td class="data"><p><?php echo get_material_info($row_readings['reading_material'],"name",1); if ($row_readings['reading_assignment'] != "") echo "<br>".$row_readings['reading_assignment']; if ($row_readings['reading_notes'] != "") echo "<br><em>".$row_readings['reading_notes']."</em>"; ?></p></td>
         <!-- Comments -->
        <td class="data">
        <?php if ($totalRows_reading_comments > 0) echo "<div class='stacked'><span class='icon'><img src='images/comment.png' align='absmiddle' border='0'></span>Yes - <a id='modal_window_link' href='index.php?section=view_comments&amp;dbTable=readings&amp;cid=".$cid."&amp;id=".$row_readings['id']."&amp;modal_window=true' title='View ID Comments'>View</a></div>"; else echo "<div class='stacked'><span class='icon'><img src='images/comment_fade.png' align='absmiddle' border='0'></span>No</div>"; if ($row_user['userLevel'] <= "2") echo "<div class='stacked'><span class='icon'><img src='images/comment_add.png' align='absmiddle' border='0'></span><a id='modal_window_link' href='index.php?section=comments&action=add&amp;cid=".$cid."&amp;dbTable=readings&amp;id=".$row_readings['id']."&amp;modal_window=true'>Add Comment</a></div>"; ?>
        </td>
        
        <!-- Changes Needed -->
        <td class="data"><?php  if ($row_reading_comments['changes'] == "Y") echo "<span class='icon'><img src='images/error.png' align='absmiddle' border='0'></span>Yes"; else echo "<span class='icon'><img src='images/tick.png' align='absmiddle' border='0'></span>No";  ?></td>
        
        <td class="data">
        <?php if ($modal_window != "true") { ?>
        <div class="stacked">
        <span class="icon"><img src="images/page_edit.png" border="0" align="absmiddle" /></span><a id="modal_window_link" href="index.php?section=module_readings&action=edit&dbTable=readings&cid=<?php echo $cid."&mid=".$row_readings['mid']."&id=".$row_readings['id']."&amp;modal_window=true"; ?>">Edit Reading Assignment</a>
        </div>
        <div class="stacked">
        <span class="icon"><img src="images/bin_closed.png" border="0" align="absmiddle" /></span><a href="javascript:confirmation('includes/process.inc.php?action=delete&dbTable=readings','id','<?php echo $row_readings['id']; ?>','Are you sure want to delete the reading assignment?')">Delete Reading</a>
        </div>
        <?php } ?>
        </td>
        
	</tr>
    <?php if ($color == $color1) { $color = $color2; } else { $color = $color1; } ?>
	<?php } while ($row_readings = mysql_fetch_assoc($readings));
	} else {
	?>
    <tr style="background-color: <?php echo $color2; ?>">
    	<td class="data" colspan="5">No readings have been entered for this module.</td>
    </tr>
    <?php } ?>
</table>
<?php } ?>